package com.example.demo.controller;

import com.example.demo.annotation.UserLoginToken;
import com.example.demo.entity.request.IdList;
import com.example.demo.service.TbMessageService;
import com.example.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api("留言板后台API")
@RestController
@RequestMapping("/admin/message")
public class AdminMessageController {

    TbMessageService messageService;
    @Autowired
    public void setMessageService(TbMessageService messageService) {
        this.messageService = messageService;
    }

    @ApiOperation("分页获取留言板")
    @GetMapping("getMessageByPage")
    public Result getMessageByPage(Integer index, Integer size) {
        Map<String, Object> messageByPage = messageService.getMessageByPage(index, size);
        return new Result(0, "success", messageByPage);
    }

    @UserLoginToken
    @ApiOperation("删除留言板")
    @ApiImplicitParam(name = "ids")
    @PostMapping("deleteMessageById")
    public Result deleteMessageById(@RequestBody @Validated IdList idList) {
        messageService.deleteMessageById(idList.getIds());
        return new Result(0, "success");
    }

}
